/**
 * 运维管理service
 */
(function(window, angular, undefined){
	/**
	 * 运维管理service
	 */
	var RemoveControlService = angular.module('RemoveControlService', ['ui.router','itfreer','waterCommon']);
	
	RemoveControlService.service('$NavService',
		function($itfreerHttp,$itfreer,$waterDataCommon,$httpData,$state,$queryObj){
			
			this.setSelectedTab = function(tabName){
				$("#removeControlDiv a[ui-sref]").removeClass("selected");
				$("#removeControlDiv a[ui-sref='"+tabName+"']").addClass("selected");
			}
			
			this.setSelectedTabSecond = function(tabName){
				$("#DataValidationSecond a[ui-sref]").removeClass("selected");
				$("#DataValidationSecond a[ui-sref='"+tabName+"']").addClass("selected");
			}
			
		});
	
	RemoveControlService.service('$OrderService',
		function($itfreerHttp,$itfreer,$waterDataCommon,$httpData,$state,$queryObj){
		
			/**
			 * mn 工控机id
			 * orders命令集合字符串,格式pollId=011,attr=CLEAR,value=1;pollId=001,attr=CLEAR,value=0;
			 * deviceId:参数设备id
			 */
			this.sendOrder = function(mn,orders,deviceId,onSuccess){
				$waterDataCommon.post("/RemoteControl/sendOrder.do",{"mn":mn,"orders":orders,"deviceId":deviceId},function(d){
					if(onSuccess){
						onSuccess(d);
					}
				});
			}
			/**
			 * 批量发送命令
			 * orders：[
			 * 	{
			 * 		poll_id:'污染物名称',
			 * 		order_code:'命令编码',
			 * 		order_value:'命令值'	
			 * 	}
			 * ]
			 */
			this.sendOrders = function(mn,orders,onSuccess){
				
				var orderStr = "";
				
				for(var i=0;i<orders.length;i++){
					var orderItem = orders[i];
					var pollId = orderItem.poll_id; // 参数id
					var attr = orderItem.order_code; // 命令
					var value = orderItem.order_value;
					if(pollId){
						orderStr += "PolID="+pollId+",";
					}
					orderStr += "Attr="+attr+",Value="+value+";";
				}
				
				$waterDataCommon.post("/RemoteControl/sendOrder.do",{"mn":mn,"orders":orderStr},function(d){
					if(onSuccess){
						onSuccess(d);
					}
				});
			}
		
		});
}(window, angular));